import { http } from '../../../utils/apiutils'
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		statusBarH: 0,  // 
		myFactory: [],
		actFactory: 0,
		userInfo: {},
		jobList: [],
		gcNum: 0,
		fxNum: 0
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function (options) {
		// setTimeout(_ => {
		// 	wx.navigateTo({
		// 		url: '/pages/home/assessment/333',
		// 	})
		// }, 1000)
	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function () {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function () {
		this.setData({
			statusBarH: getApp().globalData.menu.height,
			statusBarTop: getApp().globalData.menu.top,
			userInfo: getApp().globalData.userInfo
		})
		this.getZc();
		this.getNum()
	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function () {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function () {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function () {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function () {

	},
	toUrl(e) {
		console.log(e.currentTarget)
		wx.navigateTo({
			url: e.currentTarget.dataset.url
		})
	},
	getZc() {
		// 获取驻场列表
		http.getMyFactory({}, res => {
			if (res.status == 200) {
				this.setData({
					myFactory: res.obj,
					jobList: []
				})
				if (res.obj.length > 0) {
					this.getFactJob()
				}
			} else {
				wx.showToast({
					title: res.msg || res.message,
					icon: "none"
				})
			}
		}, err => { })
	},
	picker(e) {
		this.setData({
			actFactory: e.detail.value
		})
		this.getFactJob()
	},
	toDetail(e) {
		let fid = e.currentTarget.dataset.fid
		let jid = e.currentTarget.dataset.jid
		wx.navigateTo({
			url: '/pages/home/postDetail/postDetail?fid=' + fid + '&&jid=' + jid,
		})
	},
	toStaff(e) {
		let id = e.currentTarget.dataset.id
		wx.navigateTo({
			url: '/pages/home/staff/staff?id=' + id,
		})
	},
	onLogin() {
		// 判断是否登录
		// console.log('isLogin', getApp().globalData.isLogin)
		if (!getApp().globalData.isLogin) {
			wx.showModal({
				title: "提示",
				content: "您还没有登录，登陆后即可享受更多服务",
				confirmText: "去登陆",
				success: function (res) {
					if (res.confirm) {
						wx.navigateTo({
							url: '/pages/login/login?ptype=home',
						})
					}
				}
			})
			return;
		}
	},
	toRz() {
		// 判断是否登录
		// console.log('isLogin', getApp().globalData.isLogin)
		if (!getApp().globalData.isLogin) {
			wx.showModal({
				title: "提示",
				content: "您还没有登录，登陆后即可享受更多服务",
				confirmText: "去登陆",
				success: function (res) {
					if (res.confirm) {
						wx.navigateTo({
							url: '/pages/login/login?ptype=home',
						})
					}
				}
			})
			return;
		}
		if (!getApp().globalData.userInfo || !getApp().globalData.userInfo.idNumber) {
			wx.navigateTo({
				url: '/pages/home/realname/realname',
			})
			// wx.showToast({
			//   title: '暂未实名，请先实名认证',
			//   icon:"none",
			//   success(){
			// 	wx.nextTick(_=>{

			// 	})
			//   }
			// })
			return false;
		}
		wx.navigateTo({
			url: '/pages/home/scan/index',
		})
	},
	saom() {
		wx.navigateTo({
			url: '../../home/scan/index',
		})
	},
	getFactJob() {
		wx.showLoading()
		http.queryJobByFactoryId({
			factoryId: this.data.myFactory[this.data.actFactory].factoryId
		}, res => {
			console.log(res)
			if (res.status == 200) {
				this.setData({
					jobList: res.obj
				})
			} else {
				wx.showToast({
					title: res.msg || res.message,
					icon: "none"
				})
			}
			wx.hideLoading()
		}, err => { })
	},
	toFx(e) {
		wx.navigateTo({
			url: '/pages/home/assessment/index?id=' + e.currentTarget.dataset.id + "&jobName=" + e.currentTarget.dataset.jobName,
		})
	},
	getNum() {
		// 获取 工厂数量和 风险数量

		http.getIndexAllNumber({}, res => {
			if (res.status == 200) {
				this.setData({
					gcNum: res.obj.factoryNum,
					fxNum: res.obj.riskNum
				})
			}
		}, err => {

		})
	}
})